﻿using BZOrderPrint.DAL;
using BZOrderPrint.DAL.Entity;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.Entity.Migrations;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace BZOrderPrint
{
    public partial class FrmWhloeOrder : Form
    {
        private BzWhloeOrderEntity BzWhloeOrderEntity { get; set; }
        private BZContext context;

        public FrmWhloeOrder(BzWhloeOrderEntity bzWhloeOrderEntity)
        {
            InitializeComponent();
            Init(bzWhloeOrderEntity);
        }

        private void Init(BzWhloeOrderEntity bzWhloeOrderEntity)
        {
            BzWhloeOrderEntity = bzWhloeOrderEntity;
            context = new BZContext(ConfigHelper.ConnString);
            textBox1.Text = bzWhloeOrderEntity.WhloeOrderCode;
            textBox2.Text = bzWhloeOrderEntity.YbOrderCode;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(textBox2.Text))
            {
                MessageBox.Show("请输入银豹开单号");
                return;
            }
            BzWhloeOrderEntity.YbOrderCode = textBox2.Text;
            context.bzWhloeOrderEntities.AddOrUpdate(BzWhloeOrderEntity);
            context.SaveChanges();
            this.DialogResult = DialogResult.OK;
            this.Close();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel;
            this.Close();
        }
    }
}